﻿<div class="page-container" id="admui-pageContent">
    <div class="page animation-fade page-forms">
        <div class="page-header">
            <h1 class="page-title">添加房源</h1>
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a class="icon wb-home" href="javascript:;">房源管理</a>
                </li>
                <li class="breadcrumb-item active">添加房源</li>
            </ol>
        </div>
        <div class="page-content">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title">添加房源信息</h3>
                </div>
                <div class="panel-body">
                    <div class="example-wrap">
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="panel-body container-fluid">
                                    <div class="nav-tabs-horizontal" data-approve="nav-tabs">
                                        <ul class="nav nav-tabs nav-tabs-line" role="tablist">
                                            <li class="nav-item active" id="ycailiao">
                                                <a id="cpljx" class="nav-link" data-toggle="tab" href="#exampleTabsLineTwo" aria-controls="exampleTabsLineTwo"
                                                   role="tab">
                                                    批量添加
                                                </a>
                                            </li>
                                            <li class="nav-item" id="chanpinggongxufangfa">
                                                <a id="cpgxx" class="nav-link" data-toggle="tab" href="#exampleTabsLineOneBaoJiaDan"
                                                   aria-controls="exampleTabsLineOneBaoJiaDan" role="tab">
                                                    单个添加
                                                </a>
                                            </li>
                                        </ul>
                                        <div class="tab-content pt-20">
                                            <div class="tab-pane active" id="exampleTabsLineTwo" role="tabpanel">
                                                <div class="row row-lg">
                                                    <div class="col-sm-12" id="divyongliao">
                                                        <div class="panel-body container-fluid">
                                                            <div class="row row-lg">

                                                                <div class="col-sm-12 col-md-12">
                                                                    <div class="example-wrap margin-sm-0" id="div_yuanliaomingcheng">
                                                                        <h4 class="example-title">所属小区</h4>
                                                                        <div class="form-group">
                                                                            <select class="form-control" id="pixiaoqu"></select>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="col-sm-6 col-md-6">
                                                                    <div class="example-wrap margin-sm-0" id="div_suoxushuliang">
                                                                        <h4 class="example-title">起始楼号:(共多少号楼实例:1-10)</h4>
                                                                        <div class="form-group">
                                                                            <input type="text" class="form-control" id="kaishilouhao" placeholder="所需数量，请填数字" />
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="col-sm-6 col-md-6">
                                                                    <div class="example-wrap margin-sm-0" id="div_suoxushuliang">
                                                                        <h4 class="example-title">结束楼号</h4>
                                                                        <div class="form-group">
                                                                            <input type="text" class="form-control" id="jieshulouhao" placeholder="所需数量，请填数字" />
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="col-sm-6 col-md-6">
                                                                    <div class="example-wrap margin-sm-0" id="div_suoxushuliang">
                                                                        <h4 class="example-title">起始层数:(每号楼多少层实例:1-10)</h4>
                                                                        <div class="form-group">
                                                                            <input type="text" class="form-control" id="kaishicengshu" placeholder="所需数量，请填数字" />
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="col-sm-6 col-md-6">
                                                                    <div class="example-wrap margin-sm-0" id="div_suoxushuliang">
                                                                        <h4 class="example-title">结束层数</h4>
                                                                        <div class="form-group">
                                                                            <input type="text" class="form-control" id="jieshuchengshu" placeholder="所需数量，请填数字" />
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="col-sm-6 col-md-6">
                                                                    <div class="example-wrap margin-sm-0" id="div_suoxushuliang">
                                                                        <h4 class="example-title">起始门数:(每层有几户实例:1-10)</h4>
                                                                        <div class="form-group">
                                                                            <input type="text" class="form-control" id="kaishimenshu" placeholder="所需数量，请填数字" />
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="col-sm-6 col-md-6">
                                                                    <div class="example-wrap margin-sm-0" id="div_suoxushuliang">
                                                                        <h4 class="example-title">结束门数</h4>
                                                                        <div class="form-group">
                                                                            <input type="text" class="form-control" id="jieshumenshu" placeholder="所需数量，请填数字" />
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="col-sm-12 col-md-12">
                                                                    <div class="example-wrap margin-sm-0">
                                                                        <h4 class="example-title"></h4> 
                                                                        <div class="form-group" style="margin-top: 28px;">
                                                                            <button type="button" class="btn btn-block btn-info" id="btn_tianjia" onclick="PiLiangTianJia();">添加</button>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="tab-pane" id="exampleTabsLineOneBaoJiaDan" role="tabpanel">
                                                <div class="row row-lg">
                                                    <div class="col-md-12">
                                                        <div class="panel-body container-fluid">
                                                            <div class="row row-lg">

                                                                <div class="col-sm-6 col-md-6">
                                                                    <div class="example-wrap margin-sm-0" id="div_yuanliaomingcheng">
                                                                        <h4 class="example-title">所属小区</h4>
                                                                        <div class="form-group">
                                                                            <select class="form-control" id="danxiaoqu"></select>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="col-sm-6 col-md-6">
                                                                    <div class="example-wrap margin-sm-0" id="div_suoxushuliang">
                                                                        <h4 class="example-title">楼号</h4>
                                                                        <div class="form-group">
                                                                            <input type="text" class="form-control" id="louhao" placeholder="所需数量，请填数字" />
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="col-sm-6 col-md-6">
                                                                    <div class="example-wrap margin-sm-0" id="div_suoxushuliang">
                                                                        <h4 class="example-title">层</h4>
                                                                        <div class="form-group">
                                                                            <input type="text" class="form-control" id="cheng" placeholder="所需数量，请填数字" />
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="col-sm-6 col-md-6">
                                                                    <div class="example-wrap margin-sm-0" id="div_suoxushuliang">
                                                                        <h4 class="example-title">门</h4>
                                                                        <div class="form-group">
                                                                            <input type="text" class="form-control" id="men" placeholder="所需数量，请填数字" />
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="col-sm-12 col-md-12">
                                                                    <div class="example-wrap margin-sm-0">
                                                                        <h4 class="example-title"></h4>
                                                                        <div class="form-group" style="margin-top: 28px;">
                                                                            <button type="button" class="btn btn-block btn-info" id="btn_tianjia" onclick="DanGeTianJia();">添加</button>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        $("#SpanFangWu").click();
        XiaoQu();
    });

    function XiaoQu() {
    
        $.ajax({
            type: 'post',
            url: '../FangYuanXinXi/GetXiaoQu',
            async: false,
            dataType: 'json',
            success: function (date) {
                var ddl = $("#pixiaoqu");
                ddl.append("<option value='0'>请选择</option>");
                $(date).each(function (key) {
                    var opt = $("<option></option>").text(date[key].xiaoQuMingCheng).val(date[key].id);
                    ddl.append(opt);
                })
            },
        })
    
        $.ajax({
            type: 'post',
            url: '../FangYuanXinXi/GetXiaoQu',
            async: false,
            dataType: 'json',
            success: function (date) {
                var ddl = $("#danxiaoqu");
                ddl.append("<option value='0'>请选择</option>");
                $(date).each(function (key) {
                    var opt = $("<option></option>").text(date[key].xiaoQuMingCheng).val(date[key].id);
                    ddl.append(opt);
                })
            },
        })
    
    }

    function PiLiangTianJia() {
        var pixiaoqu = jQuery("#pixiaoqu").val();
        var kaishilouhao = $("#kaishilouhao").val();
        var jieshulouhao = $("#jieshulouhao").val();
        var kaishicengshu = $("#kaishicengshu").val();
        var jieshuchengshu = $("#jieshuchengshu").val();
        var kaishimenshu = $("#kaishimenshu").val();
        var jieshumenshu = $("#jieshumenshu").val();
        if (pixiaoqu == "0") {
            alert("请选择小区");
        } else if (kaishilouhao == "") {
            alert("请输入开始楼号");
        } else if (jieshulouhao == "") {
            alert("请输入结束楼号");
        } else if (kaishicengshu == "") {
            alert("请输入开始层数");
        } else if (jieshuchengshu == "") {
            alert("请输入结束层数");
        } else if (kaishimenshu == "") {
            alert("请输入开始门数");
        } else if (jieshumenshu == "") {
            alert("请输入结束门数");
        } else { 
        document.getElementById("btn_tianjia").disabled = true; 
        $.ajax({
            type: 'post',
            url: '../FangYuanXinXi/PiLiangTianJia',
            dataType: 'text',
            async: true,
            data: { pixiaoqu: pixiaoqu, kaishilouhao: kaishilouhao, jieshulouhao: jieshulouhao, kaishicengshu: kaishicengshu, jieshuchengshu: jieshuchengshu, kaishimenshu: kaishimenshu, jieshumenshu: jieshumenshu },
            success: function (result) {
                if (result == "1") {
                    var boo = confirm('添加成功! 是否跳转到房屋列表页面?')
                    if (boo) {
                        location.href = "../FangYuanXinXi/FangYuanXinXiList";
                    } else {
                        $("#kaishilouhao").val("");
                        $("#jieshulouhao").val("");
                        $("#kaishicengshu").val("");
                        $("#jieshuchengshu").val("");
                        $("#kaishimenshu").val("");
                        $("#jieshumenshu").val("");
                        document.getElementById("btn_tianjia").disabled = false; 
                    }
                } else {
                    alert("添加失败");
                    document.getElementById("btn_tianjia").disabled = false; 
                }
            }
        });
        }
    }

    function DanGeTianJia() {
        var danxiaoqu = jQuery("#danxiaoqu").val();
        var louhao = $("#louhao").val();
        var cheng = $("#cheng").val();
        var men = $("#men").val();
        if (danxiaoqu == "0") {
            alert("请选择小区");
        } else if (louhao == "") {
            alert("请输入楼号");
        } else if (cheng == "") {
            alert("请输入层数");
        } else if(men == ""){
            alert("请输入门数");
        } else {
        $.ajax({
            type: 'post',
            url: '../FangYuanXinXi/DanGeTianJia',
            dataType: 'text',
            async: true,
            data: { danxiaoqu: danxiaoqu, louhao: louhao, cheng: cheng, men: men, },
            success: function (result) {
                if (result == "1") {
                    var boo = confirm('添加成功! 是否跳转到房屋列表页面?')
                    if (boo) {
                        location.href = "../FangYuanXinXi/FangYuanXinXiList";
                    } else {
                        $("#louhao").val("");
                        $("#cheng").val("");
                        $("#men").val("");
                    }
                } else if (result == "3")  {
                    alert("数据库有这条数据");
                }else{
                    alert("添加失败");
            }
            }
        });
        }
    }
    
</script>